<?php

$mFormRollback = new FormRecovery($_POST);
$mValidation = new InputValidation();
$mFunction = new Fungsi();


$mValidation->SetInput($_POST['fAct']);
$mValidation->SetPattern(pAct);
$mAct = $mValidation->CheckValidation();

//SETUP PERSON
$mValidation->SetInput($_POST['fId']);
$mValidation->SetPattern(pUserId);
$tUserId = $mValidation->CheckValidation();

//SETUP USER
$mUser = new CoreUser($tUserId);
$tUsername = $mUser->GetUsername();


//SETUP DEFAULT PWD
//def password=tanggal lahir
$mPerson = new CorePerson($tUserId);
$tDefaultPwd = $mPerson->GetTanggalLahir();


//$tGoto= "main.php?menu=11&submenu=111";
if ($mAct == 'rst') {
    //SETUP LOGGED
    $mLogged = new Logged();
    $mLogged->SetUsername($tUsername);
    $mLogged->SetPassword($tDefaultPwd);
    ////

    $tSalt = $mUser->GetSalt();
    $tPwdHash = $mLogged->GeneratePasswordHash($tSalt);

    $mFunction->SetVariableToMultiFormVariableSupport('fCurrentPKValue', $tUserId, false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fPasswordHash', $tPwdHash, false, false);
    $mFunction->SetVariableToMultiFormVariableSupport('fSalt', $tSalt, false, false);

    //SETUP Nama Tabel
    $mData = new DBQueryExecute();
    $mData->SetTargerURL("main.php?menu=99&submenu=321");
    $mData->SetTableName("app_user");
    $mData->SetMultiForm(false);
    
    $mData->SetPrimaryKey('person_id', 'fId', pUserId);
    $mData->SetField('pwd', 'fPasswordHash', pPass);
    $mData->SetField('salt', 'fSalt', pUnsignedInt);


    if (!$mData->GetError())
        $tResult = $mData->ExecuteQuery('edt');
} else {
    if (!$mAct && $_POST['act']) {
        // ERROR: aksi tidak diketahui. kemungkinan diubah oleh user
    } else {
        // ERROR: nilai aksi tidak didefinisikan
    }
}
?>
